	<template>
	<view class="receivedQuotation">
		<view class="titleBox bbf1">
			<view class="titleBoxL">
				
			</view>
			<view  @tap="goNexts()">
				
			</view>
		</view>
		<view class="scrollBox" v-if="height">
			<view class="scrollBoxL">
				<scroll-view scroll-y="true" :style="{height:height + 'px'}">
					<view class="productBox" v-for="(item, index) in list" :key="index" @tap="change(index)"
						:class="{choosedProductBox : index === choosed}">
						<view class="productBoxT">
							<view class="pr img60">
								<image referrerPolicy='no-referrer' :src="item.redrawing" mode="aspectFill"
									class="img60" v-if='item.redrawing'
									:style="{filter:item.status == 4 || item.status == 5 || item.is_deal == 1 ? 'grayscale(100%)' : '' }" style="vertical-align: bottom;">
								</image>
								<image src="../../static/none.png" mode="aspectFill" class="img60" v-else
									:style="{filter:item.status == 4 || item.status == 5 || item.is_deal == 1 ? 'grayscale(100%)' : '' }" style="vertical-align: bottom;">
								</image>
								<view class="bj" v-if='item.is_deal == 1' style="background-color: #FF0000;color: #FFF;">
									已完成
								</view>
								<view class="bj" v-else-if="item.status == 4 || item.status == 5"
									style="background-color: #9DA3B0;">
									已完成
								</view>
								<view class="bj" v-else>
									报价中
								</view>
								<p class="dot-num"
									:style="{'background' : item.view_quotation_count > 0 ? 'red' : '#9DA3B0'}">
									{{ item.view_quotation_count > 0 ? '+' + item.view_quotation_count : item.quotation_count }}
								</p>
							</view>
						</view>
						<view class="productTitle">
							{{ item.spare_parts_name }}
						</view>
						<view class="colorBlock" v-if="index === choosed">

						</view>
					</view>
				</scroll-view>
			</view>
			<view class="scrollBoxR">
				<scroll-view scroll-y="true" :style="{height:height + 'px'}" v-if="quotationList.length > 0">
					<view class="orderBox" v-for="(item, index) in quotationList" :key="index">
						<view class="dot" v-if="item.view_status == 1">

						</view>
						<image src="https://cdn.xtwaixie.com/uploads/20240415/1713163836661cce3c03f45.png" mode="widthFix" style="position: absolute;top: 50%;width: 130rpx;height:auto;transform: translateY(-50%);right: 170rpx;" v-if="item.status == 3"></image>
						<view class="" style="display: flex;align-items: center;justify-content: space-between;">
							<view class="orderTitle">
								{{ item.user ? item.user.company : '' }}
							</view>
							<view class="orderInfoMoney">
								{{ item.price }}元
							</view>
						</view>

						<view class="orderInfo">
							<view class="orderInfoL">
								<view class="">
									{{ item.user.province }} {{ item.user.city }}
								</view>
								<view class="">
									{{ item.created_at }}
								</view>
							</view>
							<view class="">
								<view class="">

								</view>
								<view class="orderInfoBtn" @click="gonext(item)">
									查看详情
								</view>
							</view>
						</view>
					</view>

				</scroll-view>
				<view class="noneOrderBox" v-else :style="{height:height + 'px'}">
					<view class="">
						<image src="@/static/order.png" mode="aspectFit" class="noneImg"></image>
						<view class="noneTitle">
							暂无工厂报价
						</view>
						<view class="">
							工厂提交的报价将会展示在这里以便您进行查看报价和联系供应商
						</view>
					</view>
				</view>
			</view>
		</view>
		<van-popup :show="showPopup" @close='showPopup = false' round custom-style='background:rgba(0,0,0,0);'>
			<view class="" style="display: flex;flex-direction: column;align-items: center;">
				<image :src="img_path + img" mode="widthFix" style="width: 600rpx;" :round='true'
					:show-menu-by-longpress="true"></image>
			</view>
		</van-popup>
		<van-popup :show="showNum" z-index='10000' :close-on-click-overlay='false'
			custom-style='background:rgba(0,0,0,0);'>
			<view class="popupBox">
				<view class="loginPopup">
					<view class="" v-if='num == 0'>
						暂无新增报价
					</view>
					<view class="" v-else>
						新增<text style="color: #FF0000;margin: 0 6rpx;">{{ num }}</text>份报价
					</view>
					<view class="" @click="close()">
						好的
					</view>
				</view>
			</view>
		</van-popup>
	</view>
</template>

<script>
	import http from '../../utils/http';
	export default {
		data() {
			return {
				img_path: http.img_path,
				choosed: 0,
				height: 0,
				list: [],
				quotationList: [],
				id: 0,
				showPopup: false,
				followType: false,
				img: '',
				num:0,
				showNum:false
			}
		},
		onReady() {
			setTimeout(() => {
				let titleBox = 0
				let that = this
				uni.createSelectorQuery().in(this).select('.titleBox').boundingClientRect((rect) => {
					titleBox = rect.height
					let systemInfo = uni.getSystemInfoSync(); //系统信息
					let custom = wx.getMenuButtonBoundingClientRect() //胶囊按钮位置信息
					let navBarHeight = (custom.top - systemInfo.statusBarHeight) *
						2 +
						custom.height //计算得出导航栏高度
					that.height = systemInfo.safeArea.height - navBarHeight - titleBox
				}).exec()

			}, 500)
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			uni.requestSubscribeMessage({
				tmplIds: ['5SQbIg20NgfTt5-y7GY8BRzxqvrinsp-GnKzQIPcNPo']
			})
			if (options.id) {
				this.id = options.id
			} else {
				let token = uni.getStorageSync('token')
				if (token) {
					this.getList();
				}
			}
			if(options.showPopup){
				http.request('user/myDemand', {
						page: 1,
						limit: 1000,
						quotation: true
					})
					.then((res) => {
						this.num = res.data.list.reduce(function(prev, cur) {
							return prev + cur.view_quotation_count;
						}, 0);
						this.showNum = true
					})
					.catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
			}
		},
		watch: {
			id(newValue, oldValue) {
				this.getList();
			},
		},
		onShow() {
			uni.$on("changeId", res => {
				this.id = res
				this.getList();
				uni.$off('changeId');
			})
			http.request('base/configData')
				.then((res) => {
					this.img = res.data.xtwxcggl
				})
				.catch((res) => {
					console.log(res);
				});

			let token = uni.getStorageSync('token')
			if (token) {
				http.request('user/getSubscribe')
					.then((res) => {
						this.followType = res.data.data
					})
					.catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
			}

		},
		methods: {
			
				close() {
					let that = this
					uni.requestSubscribeMessage({
						tmplIds: ['5SQbIg20NgfTt5-y7GY8BRzxqvrinsp-GnKzQIPcNPo'],
						complete(res) {
							that.showNum = false
						}
					})
				},
			goNexts() {
				this.showPopup = true
			},
			gonext(item) {
				let that = this
				uni.requestSubscribeMessage({
					tmplIds: ['5SQbIg20NgfTt5-y7GY8BRzxqvrinsp-GnKzQIPcNPo'],
					complete(res) {
						uni.navigateTo({
							url: `/pages/quotationDetail/quotationDetail?type=supplier&id=${item.demand_id}&quotationId=${item.id}&topId=${that.list[that.choosed].id}`
						})
					}
				})
				
			},
			getList(limit = 10) {
				let data = {
					page: 1,
					limit: limit,
					quotation: true
				};
				http.request('user/myDemand', data)
					.then((res) => {
						this.list = res.data.list
						if (this.id !== 0) {
							this.list.forEach((item, index) => {
								if (item.id == this.id) {
									this.choosed = index
								}
							})
						}
						if (this.choosed > 0 && this.list[this.choosed]) {
							this.id = this.list[this.choosed].id
						} else {
							this.choosed = 0
						}
						if (res.data.recordCount > limit) {
							this.getList(res.data.recordCount)
						} else if (this.list.length > 0) {
							if (this.id === 0) {
								this.myQuotationList(this.list[0].id)
							} else {
								this.myQuotationList(this.id)
							}
							console.log(this.list[0].id)
						}
					})
					.catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
			},
			change(index) {
				if (this.choosed !== index) {
					this.choosed = index
					this.myQuotationList(this.list[index].id)
				}
			},
			myQuotationList(id) {
				this.quotationList = []
				let data = {
					id
				};
				http.request('user/myQuotationList', data)
					.then((res) => {
						this.quotationList = res.data.list
					})
					.catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F8FC;
	}

	.receivedQuotation {
		.dot-num {
			border-radius: 500rpx;
			color: #fff;
			font-size: 20rpx;
			position: absolute;
			top: -10rpx;
			right: -10rpx;
			width: 35rpx;
			text-align: center;
			line-height: 35rpx;
		}

		.scrollBox {
			display: flex;
			justify-content: space-between;

			.scrollBoxL {
				width: 25%;
				background-color: #F7F8FC;

				.choosedProductBox {
					background: #FFF;
				}

				.productBox {
					width: 100%;
					padding: 20rpx 0rpx 20rpx 35rpx;
					border-bottom: 1rpx solid #e8e8e8;
					box-sizing: border-box;
					position: relative;

					.productBoxT {
						display: flex;
						align-items: center;
						margin-bottom: 8rpx;

						.productNum {
							font-size: 28rpx;
							margin-left: 20rpx;
						}
					}

					.productTitle {
						font-size: 28rpx;
						color: #000;
						overflow: hidden;
						/*   超出容器的部分影响  */
						white-space: nowrap;
						/*  文本不换行   */
						text-overflow: ellipsis;
						/*  超出容器的文本显示省略号  */
					}

					.colorBlock {
						position: absolute;
						left: 0;
						top: 20rpx;
						height: 120rpx;
						width: 10rpx;
						background-color: rgba(16, 80, 199, 1);
					}
				}
			}

			.scrollBoxR {
				width: 75%;
				background-color: #FFF;

				.noneOrderBox {
					display: flex;
					align-items: center;
					justify-content: center;

					>view {
						display: flex;
						align-items: center;
						justify-content: space-between;
						flex-direction: column;
						width: 80%;
						height: 350rpx;

						view {
							font-size: 26rpx;
							text-align: center;
							line-height: 1.5;
						}
					}

					.noneImg {
						width: 200rpx;
						height: 200rpx;
					}

					.noneTitle {
						font-size: 28rpx;
					}
				}

				.orderBox {
					width: 98%;
					margin: 10rpx auto;
					background: #F5F3F4;
					box-sizing: border-box;
					padding: 20rpx;
					border-radius: 10rpx;
					position: relative;

					.dot {
						position: absolute;
						right: 0rpx;
						top: 0rpx;
						width: 15rpx;
						height: 15rpx;
						border-radius: 50%;
						background: #F00;
					}

					.orderTitle {
						color: #262626;
						font-size: 28rpx;
						margin-bottom: 8rpx;
						width: 350rpx;
						word-break: break-all;
					}

					.orderInfoMoney {
						color: #FEA602;
						font-size: 28rpx;
						font-weight: bold;
					}

					.orderInfo {
						display: flex;
						align-items: center;
						justify-content: space-between;

						view {
							font-size: 24rpx;
						}

						>view {
							height: 75rpx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;
						}

						.orderInfoL {
							color: #9DA3B0;
						}



						.orderInfoBtn {
							border: 2rpx solid #0239BA;
							padding: 5rpx 20rpx;
							border-radius: 10rpx;
							color: #FFF;
							font-size: 28rpx;
							font-weight: bold;
							background-color: #0239BA;
						}
					}
				}
			}
		}

		.titleBox {
			width: 750rpx;
			// height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			box-sizing: border-box;
			padding: 0 25rpx;

			.titleBoxL {
				color: #373334;
				font-size: 28rpx;
				margin-right: 15rpx;
			}

			.titleBoxR {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #01C060;
				color: #FFF;
				padding: 5rpx;
				padding-left: 10rpx;
				border-radius: 50rpx;

				image {
					width: 38rpx;
					height: 38rpx;
					margin-left: 5rpx;
				}

				view {
					font-size: 28rpx;
				}
			}
		}
	}

	.codeView {
		text-align: center;
		width: 350rpx;
		font-size: 24rpx;
		padding-bottom: 20rpx;
	}
	.popupBox {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.loginPopup {
		width: 550rpx;
		height: 200rpx;
		background-color: #FFF;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-evenly;
		align-items: center;
	}
	
	.loginPopup>view:first-child {
		color: #000;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	.loginPopup>view:last-child {
		font-size: 30rpx;
		border-radius: 12rpx;
		font-weight: bold;
		color: #FFF;
		padding: 15rpx 170rpx;
		background-color: #01C060;
	}
</style>